<?php

class Sponsors_model extends CI_Model {
    
    private $table;

    function __construct() {
        parent::__construct();
        $this->table = 'sponsors';
    }
    
    /*Ajouter un sponsor*/
    function ajouter($nom, $description, $logo, $link){
        $data = array(
            'nom' => $nom,
            'description' => $description,
            'logo' => $logo,
            'link' => $link
        );
        $this->db->insert($this->table, $data);
    }
    
    /*modifier un sponsor*/
    function modifier($id, $nom, $description, $logo, $link){
        $sponsor = $this->db->get_where($this->table, array('id_sponsor = ' . $id));
        if($sponsor->num_rows() > 0){
            
        }
        $array = array_merge($array1, $_);
        
        if($array == null) return false;
    }
    
    /*Supprimer un sponsor*/
    function supprimer($id = null){
        if($id == null || !is_numeric($id)) return false;
        $sponsor = $this->find($id);
        if($sponsor != false):
            $this->db->delete($this->table, array('id_sponsor' => $sponsor->id_sponsor));
        endif;
        
        return true;
    }
    
    /*Récupère les sponsors ...*/
    function find_all(){
        $sponsors = $this->db->get($this->table);
        
        if($sponsors->num_rows() > 0):
            return $sponsors->result();
        endif;
        
        return false;
    }
    
    /*Récupère le sponsor avec un ID ...*/
    function find($id){
        $sponsor = $this->db->get_where($this->table, array('id_sponsor' => $id))->first_row();
        if($sponsor != false){
            return $sponsor;
        }
        
        return false;
    }
    
}
